package com.ssyx.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ssyx.common.result.Result;
import com.ssyx.model.product.SkuInfo;
import com.ssyx.product.service.SkuInfoService;
import com.ssyx.vo.product.SkuInfoQueryVo;
import com.ssyx.vo.product.SkuInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:SkuInfoController
 * Description:
 *
 * @Author kay
 * @Create 2024/4/28 17:04
 * @Version 1.0
 */
@Tag(name = "商品Sku管理")
@RestController
@RequestMapping("/admin/product/skuInfo")
//@CrossOrigin
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    @Operation(summary = "获取sku分页列表")
    @GetMapping("{page}/{limit}")
    public Result index(@PathVariable Long page,
                        @PathVariable Long limit,
                        SkuInfoQueryVo skuInfoQueryVo){
        Page<SkuInfo> pageParams = new Page<>(page,limit);
        IPage<SkuInfo> pageModel = skuInfoService.getPage(pageParams,skuInfoQueryVo);
        return Result.ok(pageModel);
    }

    @Operation(summary = "新增商品")
    @PostMapping("save")
    public Result save(@RequestBody SkuInfoVo skuInfoVo) {
        skuInfoService.saveSkuInfo(skuInfoVo);
        return Result.ok(null);
    }

    @Operation(summary = "获取商品sku信息")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable Long id){
        SkuInfoVo skuInfoVo = skuInfoService.getSkuInfoVoById(id);
        return Result.ok(skuInfoVo);
    }

    @Operation(summary = "修改商品sku信息")
    @PutMapping("update")
    public Result updateById(@RequestBody SkuInfoVo skuInfoVo){
        skuInfoService.updateSkuInfo(skuInfoVo);
        return Result.ok(null);
    }

    //要删除SkuInfo,SkuPoster,SkuImage,SkuAttrValue这4张表对应的信息
    @Operation(summary = "根据id删除商品sku信息")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        skuInfoService.removeSkuById(id);
        return Result.ok(null);
    }

    @Operation(summary = "商品审核")
    @GetMapping("check/{skuId}/{status}")
    public Result check(@PathVariable Long skuId,
                        @PathVariable Integer status){
        skuInfoService.check(skuId,status);
        return Result.ok(null);

    }

    @Operation(summary = "商品上下架")
    @GetMapping("publish/{skuId}/{status}")
    public Result publish(@PathVariable Long skuId,
                        @PathVariable Integer status){
        skuInfoService.publish(skuId,status);
        return Result.ok(null);

    }

    @Operation(summary = "设置新人专享")
    @GetMapping("isNewPerson/{skuId}/{status}")
    public Result isNewPerson(@PathVariable("skuId") Long skuId,
                              @PathVariable("status") Integer status) {
        skuInfoService.isNewPerson(skuId, status);
        return Result.ok(null);
    }

}
